package com.example.osixaffairssystem.service.impl;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.model.Schedule;
import com.example.osixaffairssystem.mapper.ScheduleMapper;
import com.example.osixaffairssystem.service.ScheduleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class ScheduleServiceImpl implements ScheduleService {

    final ScheduleMapper scheduleMapper;

    @Override
    public List<Schedule> list() {
        return scheduleMapper.list();
    }

    @Override
    public PageBean<Schedule> listToPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<Schedule> p = (Page<Schedule>) scheduleMapper.list();
        return new PageBean<>(p.getTotal(), p.getResult());
    }

    @Override
    public Integer insert(Schedule schedule) {
        scheduleMapper.insert(schedule);
        return schedule.getId();
    }

    @Override
    public void update(Schedule schedule) {
        scheduleMapper.update(schedule);
    }

    @Override
    public void delete(List<Integer> ids) {
        scheduleMapper.delete(ids);
    }
}
